package com.harveyguo.nihonngo.repositories;

import com.harveyguo.nihonngo.model.entity.Coach;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 教练Repository
 */
@Repository
public interface CoachRepository extends JpaRepository<Coach, String> {

    /**
     * 根据拳馆ID查找教练
     */
    List<Coach> findByBoxingGymId(String gymId);

    /**
     * 根据认证状态查找教练
     */
    List<Coach> findByIsVerified(Boolean isVerified);

    /**
     * 根据专长领域查找教练
     */
    List<Coach> findBySpecialityContaining(String speciality);

    /**
     * 根据地理位置查找附近的教练
     */
    @Query("SELECT c FROM Coach c WHERE " +
            "SQRT(POWER(c.latitude - :latitude, 2) + POWER(c.longitude - :longitude, 2)) <= :radius")
    List<Coach> findNearbyCoaches(@Param("latitude") Double latitude,
            @Param("longitude") Double longitude,
            @Param("radius") Double radius);
}